<template>
  <el-container direction="vertical">

    <navMenu width="100%"></navMenu>

    <el-container direction="horizontal">
      <el-aside width="280px" height="100%">
        <sideBar class="menu" page-index="4-2" open-index="4"></sideBar>
      </el-aside>
      <el-main>
        <!--        <p>this is subcom page</p>-->
        <!--搜索栏-->
        <el-container direction="horizontal">
          <el-input v-model="words.word" placeholder="请输入事故类型名称 （支持模糊查询）"></el-input>
          <el-button style="margin-left: 20px" @click="vague()">搜索</el-button>
          <el-button @click="drawer = true" type="primary" style="margin-left: 16px;">添加</el-button>
          <el-drawer
            title="新增事故类型"
            :visible.sync="drawer"
            :direction="direction"
            ref="thisdrawer">

            <el-row :gutter="20">
              <el-col :span="6" :offset="2">事故名称</el-col>
            </el-row>
            <el-row :gutter="20" style="margin-top: 12px">
              <el-col :span="20" :offset="2" ><el-input v-model="newaccinfo.name" placeholder="请输入事故名称" clearable ></el-input></el-col>
            </el-row>
            <el-row :gutter="20" style="margin-top: 30px">
              <el-col :span="6" :offset="2">事故类型</el-col>
            </el-row>
            <el-row :gutter="20" style="margin-top: 12px">
              <el-col :span="20" :offset="2" ><el-input v-model="newaccinfo.type" placeholder="请输入事故类型" clearable ></el-input></el-col>
            </el-row>

            <el-row :gutter="20" style="margin-top: 30px">
              <el-col :span="6" :offset="2">事故结果</el-col>
            </el-row>
            <el-row :gutter="20" style="margin-top: 12px">
              <el-col :span="20" :offset="2" ><el-input v-model="newaccinfo.result" placeholder="请输入事故结果" clearable ></el-input></el-col>
            </el-row>

            <el-row :gutter="20" style="margin-top: 30px">
              <el-col :span="6" :offset="2">处理方法</el-col>
            </el-row>
            <el-row :gutter="20" style="margin-top: 12px">
              <el-col :span="20" :offset="2" >
                <el-input
                  type="textarea"
                  :rows="5"
                  v-model="newaccinfo.method"
                  placeholder="请输入处理方法"
                  clearable ></el-input></el-col>
            </el-row>

            <el-row :gutter="20" style="margin-top: 40px">
              <el-col :span="6" :offset="2">
                <el-button @click="newsub()" type="primary" style="width: 130%">确认提交</el-button></el-col>
            </el-row>
          </el-drawer>
        </el-container>
        <!--分公司列表-->
        <el-table
          :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
          @selection-change="handleSelectionChange"
          height="502"
          style="width: 100%; margin-top: 20px">


          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="处理方法">
                  <span>{{ props.row.acc_method}}</span>
                </el-form-item>
                <br>
                <el-form-item label="处理结果">

                  <span>{{ props.row.acc_result}}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>

          <el-table-column
            prop="acc_id"
            label="序号">
          </el-table-column>

          <el-table-column
            prop="acc_name"
            label="事故名称" >
          </el-table-column>

          <el-table-column
            prop="acc_type"
            label="事故类型">
          </el-table-column>



          <el-table-column
            prop="acc_time"
            label="发生时间">
          </el-table-column>

        </el-table>
        <!--角标-->
        <div style="text-align: center;margin-top: 20px;">
          <el-pagination
            background
            layout="prev, pager, next"
            :total="total"
            @current-change="current_change">
          </el-pagination>
        </div>

      </el-main>
    </el-container>
  </el-container>

</template>

<script>
import sideBar from "@/components/sideBar";
import navMenu from "@/components/navMenu";
export default {
  components: {sideBar, navMenu},
  data() {
    return {
      tableData: [],
      total: 0,
      pagesize: 8,
      currentPage: 1,
      st: 2,
      words: {
        word: ''
      },
      drawer: false,
      drawer2: false,
      direction: 'rtl',
      options: [{
        value: '高梁桥地铁集团',
        label: '高梁桥地铁集团'
      }],
      newaccinfo: {
        name: '',
        type: '',
        method: '',
        result:''
      },
      line: {subcom_name: '', super_company_name: ''},
      editsubinfo: {
        name: '',
        describe: '',
        method: '',
      }
    }
  },
  mounted() {
    this.$axios.get(`http://127.0.0.1:5000/accRecord/init`).then((res) => {
      console.log(res);
      this.tableData = res.data;
      this.total = this.tableData.length;
      this.total = this.tableData.length;
      console.log(this.total);
      console.log(res.data);
    });
  },
  methods: {
    current_change: function(currentPage){
      this.currentPage = currentPage;
    }, async vague() {
      this.$axios.post(`http://127.0.0.1:5000/accRecord/select`, this.words).then((res) => {
        console.log(res);
        if(res.data==0){
          this.$message('没有符合查询条件的结果');
        }
        else {
          this.$message('查询成功');
          this.tableData = res.data;
          this.total = this.tableData.length;
        }
      });
    },
    async newsub() {
      this.$axios.post(`http://127.0.0.1:5000/accRecord/newacc`, this.newaccinfo).then((res) => {
        console.log(res);
        this.st = res.data;

        if (this.st==1) {
          this.$message('新增成功');
          this.$refs.thisdrawer.closeDrawer();
          window.location.reload();
        }
        else {
          this.$message('新增失败，已存在！');
          this.$refs.thisdrawer.closeDrawer();
        }
        this.st=2;

      });
    }
  }
}
</script>

<style>


.menu{
  width: 100%;
  float: left;
  height: 700px;
}

</style>
